/** form *********************************************/
export class MenuForm {
    public menuId?: string;
    public menuParentId!: string;
    public name!: string;
    public key!: string;
    public icon!: string;
    public orderIndex: number = 999;
    public link: boolean = false;
    public url!: string;
    public permission!: string;
    public display: boolean = true;
    public enabled: boolean = true;

    public static rules = {
        name: [
            { required: true, message: '请输入名称', trigger: 'blur' },
            { max: 10, message: '请确认输入不超过10个字符', trigger: 'blur' },
        ],
        permission: [{ required: true, message: '请输入权限字符', trigger: 'blur' }],
    };
}

/** query *********************************************/
export class MenuQuery {
    public name!: string;
}

/** dto *********************************************/
export class MenuListDTO {
    public menuId!: string;
    public menuParentId!: string;
    public name!: string;
    public key!: string;
    public icon!: string;
    public orderIndex!: number;
    public link!: boolean;
    public url!: string;
    public permission!: string;
    public display!: boolean;
    public enabled!: boolean;

    public static columns = [
        {
            title: '名称',
            dataIndex: 'name',
        },
        {
            title: '顺序',
            dataIndex: 'orderIndex',
            align: 'center',
            width: 60,
        },
        {
            title: '权限标识',
            dataIndex: 'permission',
            width: 200,
        },
        {
            title: '显示状态',
            dataIndex: 'display',
            align: 'center',
            width: 100,
        },
        {
            title: '启用状态',
            dataIndex: 'enabled',
            align: 'center',
            width: 100,
        },
        {
            title: '操作',
            dataIndex: 'action',
            width: 200,
            fixed: 'right',
        },
    ];
}

export class MenuDTO extends MenuListDTO {
    public transToForm = (): MenuForm => {
        const form = new MenuForm();
        Object.keys(form).forEach((key) => {
            if (this[key]) {
                form[key] = this[key];
            }
        });
        return form;
    };
}

export class MenuDictDTO {
    public key!: string;
    public value!: string;
    public title!: string;
    public children!: MenuDictDTO[];
}
